<?php

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use models\Factory;
use util\CommonUtil;
use util\Constant;

include '../autoload.php';
require_once('../vendor/autoload.php');

header("Content-Type: text/html; charset=UTF-8");
ini_set('memory_limit','2650M');


$ua = CommonUtil::getPcUserAgent();
if (empty($ua)) {
    CommonUtil::echoStr("\nUA初始化失败，执行下次任务\n");
    exit();
}

CommonUtil::echoStr("\nUA:{$ua}\n");

// start Firefox with 5 second timeout
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::chrome();
//$options = new ChromeOptions();
//$options->addArguments(["user-agent={$ua}"]);
//$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = RemoteWebDriver::create($host, $capabilities, Constant::$CONNECTION_TIMEOUT_IN_MS);
$driver->manage()->timeouts()->implicitlyWait(Constant::$IMPLICITLY_WAIT);
$driver->manage()->window()->maximize();    //将浏览器最大化

$driver->get('http://www.meituan.com/deal/40124554.html');   //先访问网页，获取到cookie权限

CommonUtil::echoStr("\n完成\n");

?>